package com.techyuan.algorithm.structure.tree;

import sun.reflect.generics.tree.Tree;

/**
 * Created by tianjuntao on 2017/1/9.
 */
public class TreeNode<T extends TreeNode> {
    private T parent;
    private T left;
    private T right;

    private Integer key;

    public TreeNode(){}
    public TreeNode(Integer key){
        this.key = key;
    }

    public TreeNode(T l,T r,T p,Integer key){
        this.left = l;
        this.right = r;
        this.parent = p;
        this.key = key;
    }

    public void setKey(Integer value) {
        this.key = value;
    }

    public Integer getKey() {
        return key;
    }

    public void setParent(T parent) {
        this.parent = parent;
    }

    public T getParent() {
        return parent;
    }

    public void setLeft(T left) {
        this.left = left;
    }

    public T getLeft() {
        return left;
    }

    public T getRight() {
        return right;
    }

    public void setRight(T right) {
        this.right = right;
    }

    public static TreeNode nil;

    static {
        nil = new TreeNode(null);
        nil.setParent(nil);
        nil.setLeft(nil);
        nil.setRight(nil);
    }

    public boolean isNil() {
        return this == nil;
    }

    public TreeNode getNil(){
        return nil;
    }

    @Override
    public String toString() {
        return String.valueOf(this.getKey());
    }
}
